import {Particle} from './particle.js'
export class Shape{
    constructor(x, y, text, option = {}){
        const {ctx, gridX = 7, gridY = 7, w, h} = option
        this.x = x
        this.y = y
        this.size = 200
        this.text = text
        this.placement = []
        this.ctx = ctx
        this.gridX = gridX
        this.gridY = gridY
        this.w = w
        this.h = h
        this.option = option
    }
    getValue(){
        let {ctx, gridY, gridX, h, w} = this
        ctx.textAlign = 'center'
        ctx.font = `${this.size}px Arial`
        ctx.fillText(this.text, this.x, this.y)
        let iData = ctx.getImageData(0, 0, w, h)
        let buffer32 = new Uint32Array(iData.data.buffer)
        for(let i = 0; i < w; i += gridX){
            for(let j = 0; j < h; j += gridY){
                if(buffer32[j * w + i]){
                    let particle = new Particle(i, j, this.option)
                    this.placement.push(particle)
                }
            }
        }
    }
}